:- use_module(iop_sib_access).

%events
event_name('ui_mode(resize)').
event_name('ui_mode(scrible)').
event_name('ui_mode(mouse)').
event_name('ui_mode(record)').
event_name('ui_mode(play)').
kp_name('lea_kp_emulator').

%url
ns_core('http://www.sofia-project.eu/ontologies/core/2010/01/19/sofia.owl#').
ns_semint('http://sofia.gotdns.com/ontologies/SemanticInteraction.owl#').
ns_sc('http://sofia.gotdns.com/ontologies/SemanticConnections.owl#').
ns_sc_add('http://sofia.gotdns.com/ontologies/SemanticConnections_UnBo.owl#').

kp_name_so('SmartObject_01').
kp_name_lea('LumEnActive_A1003').

init:-
join_sib('192.168.5.211','X',10010),
insert_triple_connection.



%functional rules
element_at([X|_],0,X):-!.
element_at([X|Ls],N,Z):- M is N-1, element_at(Ls,M,Z),!.

%kp uri
smartObject_uri(X):- kp_name_so(Y), ns_core(Z), concat(Z,Y,X).
lea_uri(X):- kp_name_lea(Y), ns_core(Z), concat(Z, Y, X).

%Connection
connnectedTo(X):- ns_sc(Y), concat(Y,'connectedTo',X).

%Smart Object event
launchesEvent(X):- ns_core(Y), concat(Y,'launchesEvent',X).
event_uri(X):- ns_core(Y), concat(Y,'Event_69',X).
event(X):- ns_core(Y), concat(Y,'Event',X).
hasEventType(X):- ns_sc_add(Y), concat(Y,'hasEventType',X).

event_lea_uri(In, Out):- ns_core(X), concat(X,In,Out).
event_lea_uri_alt(Num, Out):- ns_core(W), findall(X, event_name(X), L), element_at(L,Num,O), concat(W,O,Out).

insert_triple_launchesEvent:- smartObject_uri(X), launchesEvent(Y), event_uri(Z), insert_sib(triple(X,Y,Z)).
insert_triple_rdfType:- event_uri(X), event(Y), insert_sib(triple(X, 'rdf:type', Y)).
insert_triple_hasEventType(In):-event_uri(X), hasEventType(Y), event_lea_uri(In,Out), insert_sib(triple(X,Y,Out)).
insert_triple_hasEventType_alt(In):-event_uri(X), hasEventType(Y), event_lea_uri_alt(In,Out), insert_sib(triple(X,Y,Out)).

%FINAL RULES
insert_triple_connection:- smartObject_uri(X), connnectedTo(Y), lea_uri(Z), insert_sib(triple(X,Y,Z)).

insert_event(X):- insert_triple_launchesEvent, insert_triple_rdfType, insert_triple_hasEventType(X).
insert_event_alt(X):- insert_triple_launchesEvent, insert_triple_rdfType, insert_triple_hasEventType_alt(X).
